package com.snackshop.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.snackshop.mapper.UserDetailMapper;
import com.snackshop.mapper.UserMapper;
import com.snackshop.pojo.model.User;
import com.snackshop.pojo.model.UserDetail;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
@Log
public class RegisterService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserDetailMapper userDetailMapper;

    @Transactional
    public Boolean register(User user){
        String userPhone = user.getUserPhone();
        Wrapper<User> userFromData = new QueryWrapper<User>().eq("user_phone", userPhone);
        if (userMapper.selectOne(userFromData)!=null){
            return false;
        }
        log.info(user.toString());
        int insert = userMapper.insert(user);
        log.info(user.toString());
        // UserDetail userDetail = new UserDetail();
        // userDetail.setUserId(user.getUserId());
        // userDetail.setUserCreateTime(new Date());
        // userDetailMapper.insert(userDetail);
        return true;

    }
}
